package org.jfonia.connect;

/**
 * Basic node class for values and mutable values, holding a validity state (boolean).
 * Useful for lazy schemes (mark and sweep).
 * 
 * callThis() will put valid=false. 
 * Deriving value-classes should put valid=true after a get() call.  
 * 
 * Note: even values which don't hold state (calculating output from input e.g.)
 * should derive from this class, 
 * 
 * @author wijnand.schepens@gmail.com
 *
 */
public class ValueNode extends BasicNode {
	protected boolean valid = true;
	
	/**
	 * override: callThis(), then only callTargets() if node was valid. Set valid=false 
	 */
	@Override
	public boolean call(Object param)
	{
		boolean r = this.callThis(param);
		if (valid)
			r = r && super.callTargets(param);
		setValid(false);
		return r;
	}
	
	public void setValid(boolean valid)
	{
		this.valid = valid;
	}
	
	public boolean isValid()
	{
		return valid;
	}
	
}
